<?php
namespace app\company\logic;

use JPush\Client as JPush;
use JPush\Exceptions\JPushException;
class JiPush{
    const app_key ='71fa809b8cc967119c34ef98';
    const master_secret ='23db04b9cc5afc664e109d0b';
    static public function push($user_id,$title,$content){
        $client = new JPush(self::app_key, self::master_secret);
        $params = [];
        $ios_badge = 0;
        $platform = ['ios', 'android'];
        try {
            $result = $client->push ()
                ->setPlatform ($platform)
                ->addAlias (strval($user_id))
                ->iosNotification (
                    $content, [
                    'sound' => '1',
                    'badge' => (int)$ios_badge,
                    'content-available' => true,
                    'category' => 'jiguang',
                    'extras' => $params,
                ])
                ->androidNotification ($content, [
                    'title' => $title,
                    //'build_id' => 2,
                    'extras' => $params,
                ])
                ->options ([
                    'sendno' => 100,
                    'time_to_live' => 86400,
                    'apns_production' => true, // ios推送证书的选择，True 表示推送生产环境，False 表示要推送开发环境
                    //'big_push_duration' => 10,
                ])
                ->send ();
            return $result;
        } catch (JPushException $e) {
            // try something else here
//            print $e;
        }
    }

}
